﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Utils;

namespace UtilsIntegrationTests
{
    [TestClass]
    public class TimeredEngineBaseIT
    {
        [TestMethod]
        public void TestNormalEngineExecution()
        {
            TestEngine engine = new TestEngine(1000);
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            Assert.AreEqual(4, engine.Count);
        }

        [TestMethod]
        public void TestRestartingEngineExecution()
        {
            TestEngine engine = new TestEngine(1000);
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            Assert.AreEqual(8, engine.Count);
        }

        [TestMethod]
        public void TestRestartingEngineExecution2()
        {
            TestEngine engine = new TestEngine(1000);
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            engine.Start();
            System.Threading.Thread.Sleep(3100);
            engine.Stop();
            Assert.AreEqual(32, engine.Count);
        }
    }

    internal class TestEngine : TimeredEngineBase
    {
        public int Count { get; private set; }

        public TestEngine(int interval) : base(interval, "Integration Test Engine")
        {
            this.Count = 0;
        }

        protected override void MainMethod()
        {
            this.Count++;
        }
    }
}
